<template>
  <div class="container-content">
    <el-form
      ref="formRef"
      :model="formObject"
      label-width="90px"
      label-position="left"
    >
      <el-card shadow="never" class="mt20">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="单据类型">
              <el-select
                v-model="formObject.docBusinessType"
                placeholder="单据类型"
                style="width: 100%"
              >
                <el-option label="标准采购入库单" value="1" checked></el-option>
                <el-option label="零散采购入库单" value="2"></el-option>
                <el-option label="委外入库单" value="3"></el-option>
                <el-option label="分销购销入库单" value="4"></el-option>
                <el-option label="资产入库单" value="5"></el-option>
                <el-option label="费用入库单" value="6"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收料部门">
              <el-input v-model="formObject.receivingDept">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('收料部门')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <!-- </el-row>
        <el-row :gutter="20"> -->
          <el-col :span="12">
            <el-form-item label="采购部门">
              <el-input v-model="formObject.purchaseDept">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('采购部门')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="采购组">
              <el-input v-model="formObject.purchaseGroup">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('采购组')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="收料日期">
              <el-date-picker
                v-model="formObject.receiveTime"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!-- </el-row>
        <el-row :gutter="20"> -->
          <el-col :span="12">
            <el-form-item label="仓管员">
              <el-input v-model="formObject.managementBy">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('仓管员')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="采购员">
              <el-input v-model="formObject.purchaseBy">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('采购员')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <!-- </el-row>
        <el-row :gutter="20"> -->
          <el-col :span="12">
            <el-form-item label="供应商">
              <el-input v-model="formObject.supplierName">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('供应商')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供货方">
              <el-input v-model="formObject.providerName">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('供货方')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供货联系人">
              <el-input v-model="formObject.providerContacts">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('供货联系人')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供货方地址">
              <el-input v-model="formObject.providerAddress" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结算方">
              <el-input v-model="formObject.balanceName">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('结算方')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收款方">
              <el-input v-model="formObject.receiveName">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('收款方')"
                ></i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱">
              <el-input v-model="formObject.email"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <div class="desc-title">入库明细</div>
      <el-table
        :data="formObject.materialLists"
        style="width: 100%"
        highlight-current-row
        border
        :key="flag"
      >
        <template #empty
          ><el-button plain type="primary" round @click="addNewRow"
            >添加新行</el-button
          ></template
        >
        <el-table-column label="操作" width="120px">
          <template slot-scope="scope">
            <el-button
              plain
              icon="el-icon-plus"
              size="small"
              @click="handleDataAdd(scope.$index, scope.row)"
            ></el-button>
            <el-button
              plain
              icon="el-icon-minus"
              size="small"
              @click="handleDataDelete(scope.$index, scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column label="入库类型">
          <template slot-scope="scope">
            <el-input v-model="scope.row.inventoryType" disabled> </el-input>
          </template>
        </el-table-column>
        <el-table-column label="物料编码">
          <template slot-scope="scope">
            <el-form-item label-width="0px" style="margin: 0">
              <el-input v-model="scope.row.materialCode">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('物料编码', scope.$index)"
                ></i>
              </el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="物料名称">
          <template slot-scope="scope">
            <el-form-item label-width="0px" style="margin: 0">
              <el-input disabled v-model="scope.row.materialName"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="规格型号">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.materialModel"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="库存单位">
          <template slot-scope="scope">
            <el-input v-model="scope.row.inventoryUnitName">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('库存单位', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="物料说明">
          <template slot-scope="scope">
            <el-input v-model="scope.row.materialDesc"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="应收数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.purchaseNum" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="实收数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.receiptsNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="计价单位">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pricingName">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('计价单位', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="计价数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pricingNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓库">
          <template slot-scope="scope">
            <el-input v-model="scope.row.warehouseName">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('仓库', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓位">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.warehousePosition"></el-input>
          </template>
        </el-table-column>

        <el-table-column label="库存状态">
          <template slot-scope="scope">
            <el-input v-model="scope.row.inventoryStatus">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('库存状态', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="批号">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.batchNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="备注">
          <template slot-scope="scope">
            <el-input v-model="scope.row.remark"> </el-input>
          </template>
        </el-table-column>
        <el-table-column label="采购单位">
          <template slot-scope="scope">
            <el-input v-model="scope.row.purchaseUnit" disabled> </el-input>
          </template>
        </el-table-column>
        <el-table-column label="采购数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.purchaseNum"> </el-input>
          </template>
        </el-table-column>
        <el-table-column label="净价">
          <template slot-scope="scope">
            <el-input v-model="scope.row.netPrice" disabled> </el-input>
          </template>
        </el-table-column>

        <el-table-column label="不良品折让金额">
          <template slot-scope="scope">
            <el-input v-model="scope.row.defectiveDiscountAmount"> </el-input>
          </template>
        </el-table-column>

        <el-table-column label="当前对账单号">
          <template slot-scope="scope">
            <el-input v-model="scope.row.currentReconciliationCode" disabled>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="历史对账单号">
          <template slot-scope="scope">
            <el-input v-model="scope.row.historyReconciliationCode" disabled>
            </el-input>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <el-dialog
      width="60%"
      :title="title"
      :visible.sync="dialogTableVisible"
      :append-to-body="appendbody"
    >
      <!-- 库存状态 -->
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '库存状态'">
        <el-table-column
          property="inventoryStatusCode"
          label="编码"
          width="150"
        ></el-table-column>

        <el-table-column property="level" label="type">
          <!-- 层级(0集团公司 1子公司 2部门) -->
          <template slot-scope="scope">
            <!-- <p v-if="scope.row.level == 0">集团公司</p>
            <p v-if="scope.row.level == 1">子公司</p>
            <p v-if="scope.row.level == 2">部门</p> -->
          </template>
        </el-table-column>
        <el-table-column
          property="inventoryStatusName"
          label="名称"
          width="200"
        ></el-table-column>
        <el-table-column
          property="isDisabled"
          label="数据状态"
        ></el-table-column>
        <el-table-column
          property="isWarning"
          label="参与预警"
        ></el-table-column>
        <el-table-column property="isUse" label="可使用"></el-table-column>
        <el-table-column
          property="isDisabledSale"
          label="不可销售"
        ></el-table-column>
        <el-table-column
          property="isDisabledApply"
          label="不可领用"
        ></el-table-column>
        <el-table-column
          property="isInventory"
          label="可锁库"
        ></el-table-column>
      </el-table>
      <!-- 供应商 -->
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '供应商'">
        <el-table-column
          property="supplierCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="supplierName"
          label="名称"
          width="200"
        ></el-table-column>
        <el-table-column property="forShort" label="简称"></el-table-column>
        <el-table-column
          property="supplierGroup"
          label="供应商分组"
        ></el-table-column>
        <el-table-column
          property="examineId"
          label="审核人"
          width="200"
        ></el-table-column>
        <el-table-column
          property="examineTime"
          label="审核日期"
        ></el-table-column>
        <el-table-column
          property="dataState"
          label="数据状态"
        ></el-table-column>
        <el-table-column
          property="disabledState"
          label="禁用状态"
        ></el-table-column>
      </el-table>
      <!-- 供货方 -->
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '供货方'">
        <el-table-column
          property="supplierCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="supplierName"
          label="名称"
          width="200"
        ></el-table-column>
        <el-table-column property="forShort" label="简称"></el-table-column>
        <el-table-column
          property="supplierGroup"
          label="供应商分组"
        ></el-table-column>
        <el-table-column
          property="examineId"
          label="审核人"
          width="200"
        ></el-table-column>
        <el-table-column
          property="examineTime"
          label="审核日期"
        ></el-table-column>
        <el-table-column
          property="dataState"
          label="数据状态"
        ></el-table-column>
        <el-table-column
          property="disabledState"
          label="禁用状态"
        ></el-table-column>
      </el-table>
      <!-- 结算方 -->
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '结算方'">
        <el-table-column
          property="supplierCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="supplierName"
          label="名称"
          width="200"
        ></el-table-column>
        <el-table-column property="forShort" label="简称"></el-table-column>
        <el-table-column
          property="supplierGroup"
          label="供应商分组"
        ></el-table-column>
        <el-table-column
          property="examineId"
          label="审核人"
          width="200"
        ></el-table-column>
        <el-table-column
          property="examineTime"
          label="审核日期"
        ></el-table-column>
        <el-table-column
          property="dataState"
          label="数据状态"
        ></el-table-column>
        <el-table-column
          property="disabledState"
          label="禁用状态"
        ></el-table-column>
      </el-table>
      <!-- 收款方 -->
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '收款方'">
        <el-table-column
          property="supplierCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="supplierName"
          label="名称"
          width="200"
        ></el-table-column>
        <el-table-column property="forShort" label="简称"></el-table-column>
        <el-table-column
          property="supplierGroup"
          label="供应商分组"
        ></el-table-column>
        <el-table-column
          property="examineId"
          label="审核人"
          width="200"
        ></el-table-column>
        <el-table-column
          property="examineTime"
          label="审核日期"
        ></el-table-column>
        <el-table-column
          property="dataState"
          label="数据状态"
        ></el-table-column>
        <el-table-column
          property="disabledState"
          label="禁用状态"
        ></el-table-column>
      </el-table>
      <!-- 供货方联系人 -->
      <el-table
        :data="gridData"
         @row-dblclick="getRow"
        v-if="title == '供货联系人'"
      >
        <el-table-column
          property="supplierId"
          label="供应商"
          width="150"
        ></el-table-column>
        <el-table-column
          property="contactsCode"
          label="编码"
          width="200"
        ></el-table-column>
        <el-table-column property="name" label="名称"></el-table-column>
        <el-table-column property="position" label="职务"></el-table-column>
        <el-table-column
          property="workTel"
          label="电话"
          width="200"
        ></el-table-column>
        <el-table-column property="mobile" label="手机"></el-table-column>
        <el-table-column property="fax" label="传真"></el-table-column>
        <el-table-column property="email" label="电子邮箱"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '收料部门'">
        <el-table-column
          property="deptCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="deptId"
          label="助记码"
          width="200"
        ></el-table-column>
        <el-table-column property="deptName" label="名称"></el-table-column>
        <el-table-column
          property="parentName"
          label="上级部门"
        ></el-table-column>
        <el-table-column
          property=""
          label="HR部门"
          width="200"
        ></el-table-column>
        <el-table-column property="status" label="数据状态"></el-table-column>
        <el-table-column property="deptName" label="部门全称"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '采购部门'">
        <el-table-column
          property="deptCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="deptId"
          label="助记码"
          width="200"
        ></el-table-column>
        <el-table-column property="deptName" label="名称"></el-table-column>
        <el-table-column
          property="parentName"
          label="上级部门"
        ></el-table-column>
        <el-table-column
          property=""
          label="HR部门"
          width="200"
        ></el-table-column>
        <el-table-column property="status" label="数据状态"></el-table-column>
        <el-table-column property="deptName" label="部门全称"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '库存组'">
        <el-table-column
          property="date"
          label="业务组编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="shipperCode"
          label="业务组名称"
          width="200"
        ></el-table-column>
        <el-table-column
          property="address"
          label="业务组类型"
        ></el-table-column>
        <el-table-column property="address" label="启用"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '仓管员'">
        <el-table-column property="nickName" label="名称"></el-table-column>
        <el-table-column property="userCode" label="职员编码"></el-table-column>
        <el-table-column property="deptName" label="部门"></el-table-column>
        <el-table-column property="isUsed" label="禁用状态"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '物料编码'">
        <el-table-column property="materialCode" label="编码"></el-table-column>
        <el-table-column property="materialName" label="名称"></el-table-column>
        <el-table-column property="model" label="规格型号"></el-table-column>
        <!-- <el-table-column property="isChange" label="数据状态"></el-table-column>
        <el-table-column property="isUsed" label="禁用状态"></el-table-column> -->
        <!-- <el-table-column
          property="materialProperty"
          label="物料属性"
        ></el-table-column> -->
        <el-table-column
          property="purchaseUnitName"
          label="基本单位"
        ></el-table-column>
        <!-- <el-table-column property="isUsed" label="已使用"></el-table-column> -->
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '库存单位'">
        <el-table-column
          property="meteringUnitCode"
          label="编码"
        ></el-table-column>
        <el-table-column
          property="meteringUnitName"
          label="名称"
        ></el-table-column>
        <el-table-column
          property="isBase"
          label="基准计量单位"
        ></el-table-column>
        <el-table-column property="isUsed" label="数据状态"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '计价单位'">
        <el-table-column
          property="meteringUnitCode"
          label="编码"
        ></el-table-column>
        <el-table-column
          property="meteringUnitName"
          label="名称"
        ></el-table-column>
        <el-table-column
          property="isBase"
          label="基准计量单位"
        ></el-table-column>
        <el-table-column property="isUsed" label="数据状态"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '仓库'">
        <el-table-column property="wareCode" label="编码"></el-table-column>
        <el-table-column property="wareName" label="名称"></el-table-column>
        <el-table-column property="address" label="仓库地址"></el-table-column>
        <el-table-column
          property="wareManagement"
          label="仓库负责人"
        ></el-table-column>
        <el-table-column property="address" label="仓库属性"></el-table-column>
        <el-table-column
          property="address"
          label="第三方仓储类型"
        ></el-table-column>
        <el-table-column property="" label="数据状态"></el-table-column>
        <el-table-column property="" label="允许即使库负库存"></el-table-column>
        <el-table-column property="" label="启用仓位管理"></el-table-column>
        <el-table-column property="" label="不参与可发量统计"></el-table-column>
        <el-table-column property="" label="参与预警"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogTableVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  addKingInventoryList,
  getdeptList,
  getMaterial,
  getKingBaseMeteringUnitList,
  getWarehouseList,
  getKingBaseBusinessGroupList,
  getKinguserList,
  getSupplierList,
  getCustomerList,
  getregionList,
  getSupplierContactsList,
  getKingInventoryStatusList,
} from "@/api/bim/bim";
export default {
  data() {
    return {
      shipper: "",
      appendbody: true,
      title: "",
      num: 0,
      flag: false,
      count: 0,
      gridData: [],
      dialogTableVisible: false,
      formObject: {
        businessType: "21",
        modelId: this.$store.state.workflow.businessConfig.id,
        balanceCode: "",
        balanceId: "",
        baseCurrency: "",
        businessType: "",
        cargoOwner: "",
        cargoOwnerType: "",
        carrier: "",
        childTye: "",
        confirmName: "",
        confirmState: "",
        confirmTime: "",
        createName: "",
        createTime: "",
        customerId: "",
        deliveryAddress: "",
        discountInfoCode: "",
        docBusinessType: "",
        docCode: "",
        docStatus: "",
        docType: "",
        email: "",
        examineName: "",
        examineTime: "",
        exchangeRate: "",
        exchangeRateType: "",
        id: "",
        instanceId: "",
        invalidName: "",
        invalidState: "",
        invalidTime: "",
        inventoryGroup: "",
        inventoryTime: "",
        isExtraPriceTax: true,
        isSend: 0,
        isTax: true,
        isUsed: 0,
        lastUpdateName: "",
        lastUpdateTime: "",
        managementBy: "",
        materialLists: [
        
        ],
        modelId: "",
        moneyAmount: "",
        payer: "",
        phone: "",
        priceInfoCode: "",
        pricingTimePoint: "",
        providerAddress: "",
        providerCode: "",
        providerContacts: "",
        providerId: "",
        purchaseBy: "",
        purchaseDept: "",
        purchaseGroup: "",
        purchaseOrg: "",
        receiveCode: "",
        receiveId: "",
        receivingDept: "",
        receivingOrg: "",
        receivingPartyAddress: "",
        receivingPartyContacts: "",
        receivingPartyName: "",
        requireDept: "",
        sendGoodsDept: "",
        sendGoodsGroup: "",
        settlementCurrency: "",
        settlementMethod: "",
        settlementOrg: "",
        state: "",
        supplierCode: "",
        supplierId: "",
        taxAmount: "",
        termOfPayment: "",
        totalPriceTax: "",
        trafficNum: "",
        type: "",
        userId: "",
        wholeDiscountAmount: "",
      },
    };
  },

  methods: {
    selectshipper(val) {
      this.shipper = val;
    },
    // 获取每次点击的内容进行区分，并在此方法内进行打开弹窗及数据的请求
    openList(item, i) {
      this.count = i;
      this.dialogTableVisible = true;
      this.title = item;

      if (this.title == "收料部门" || this.title == "采购部门") {
        getdeptList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.data;
          }
        });
      } else if (this.title == "部门") {
        getdeptList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.data;
          }
        });
      } else if (this.title == "库存组") {
        this.gridData = [];
      } else if (this.title == "采购组") {
        this.gridData = [];
      } else if (this.title == "仓管员") {
        getKinguserList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (this.title == "采购员") {
        getKinguserList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (this.title == "物料编码") {
        getMaterial().then((res) => {
          if (res.code == 200) {
            this.gridData = res.data.records;
          }
        });
      } else if (this.title == "库存单位" || this.title == "计价单位") {
        getKingBaseMeteringUnitList().then((res) => {
          this.gridData = res.rows;
        });
      } else if (this.title == "仓库") {
        getWarehouseList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (this.title == "供应商") {
        getSupplierList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (
        this.title == "供货方" ||
        this.title == "结算方" ||
        this.title == "收款方"
      ) {
        getSupplierList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
        // 客户组织
      } else if (this.title == "供货联系人") {
        getSupplierContactsList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
        // 客户组织
      } else if (this.title == "库存状态") {
        console.log(66);

        getKingInventoryStatusList().then((res) => {
          console.log(res);

          this.gridData = res.rows;
        });
      }
    },
    // 获取点击的表格内容并且关闭弹窗且进行内容的回显
    getRow(row) {
      this.dialogTableVisible = false;
      if (this.title == "收料部门" ) {
      this.formObject.receivingDept=row.deptName
      }else if( this.title == "采购部门"){
         this.formObject.purchaseDept=row.deptName
      }
      else if (this.title == "部门") {
       
      } else if (this.title == "库存组") {
        this.gridData = [];
      } else if (this.title == "采购组") {
        this.gridData = [];
      } else if (this.title == "仓管员") {
         this.formObject.managementBy=row.nickName
      } else if (this.title == "采购员") {
        this.formObject.purchaseBy=row.nickName
      } else if (this.title == "物料编码") {
       this.formObject.materialLists[this.count].materialCode=row.materialCode
       this.formObject.materialLists[this.count].materialName=row.materialName
       this.formObject.materialLists[this.count].inventoryUnit=row.purchaseUnitName
       this.formObject.materialLists[this.count].materialModel=row.model
      //  this.formObject.materialLists[this.count].materialDesc=row.materialCode
       this.formObject.materialLists[this.count].pricingUnit=row.purchaseUnitName
      //  this.formObject.materialLists[this.count].inventoryStatus=row.materialCode
       this.formObject.materialLists[this.count].purchaseUnit=row.purchaseUnitName
      } else if (this.title == "库存单位") {
        this.formObject.materialLists[this.count].inventoryUnit=row.isBase
        this.formObject.materialLists[this.count].inventoryUnitName=row.meteringUnitName
      }else if(this.title == "计价单位"){
 this.formObject.materialLists[this.count].pricingUnit=row.isBase
        this.formObject.materialLists[this.count].pricingName=row.meteringUnitName
      }
       else if (this.title == "仓库") {
      this.formObject.materialLists[this.count].warehouseId=row.wareCode
      this.formObject.materialLists[this.count].warehouseName=row.wareName
      } else if (this.title == "供应商") {
       this.formObject.supplierCode=row.id
       this.formObject.supplierName=row.supplierName
      } else if (
        this.title == "供货方" 
      ) {
       this.formObject.providerId=row.id
       this.formObject.providerName=row.supplierName
        // 客户组织
      }else if ( this.title == "结算方" 
       ) {
        this.formObject.balanceId=row.id
        this.formObject.balanceName=row.supplierName
      }else if ( this.title == "收款方") {
        this.formObject.receiveId=row.id
        this.formObject.receiveName=row.supplierName
      }
       else if (this.title == "供货联系人") {
       this.formObject.providerContacts=row.name
        // 客户组织
      } else if (this.title == "库存状态") {
       this.formObject.managementBy=row.nickName
      }
    },
    selectProject() {},
    handleDataAdd() {
      if (this.formObject.kingProfitLossDetailEntities == undefined) {
        this.formObject.kingProfitLossDetailEntities = [];
      }
      let obj =   {
            batchNum: "",
            businessPrice: "",
            businessTaxPrice: "",
            changeTime: "",
            createTime: "",
            currentReconciliationCode: "",
            defectiveDiscountAmount: "",
            historyReconciliationCode: "",
            id: "",
            inventoryId: "",
            inventoryStatus: "",
            inventoryType: "",
            inventoryUnit: "",
            isGiveaway: true,
            isReconciliation: true,
            isUsed: 0,
            lineNumber: "",
            materialCode: "",
            materialDesc: "",
            materialDetail: {
              amountMoney: "",
              amountMoneyBase: "",
              auxiliaryUnit: "",
              batchNum: "",
              bomVer: "",
              businessProcess: "",
              changeTime: "",
              containsTaxPrice: "",
              createTime: "",
              discountAmount: "",
              discountRate: "",
              entryPriceList: "",
              id: "",
              inventoryId: "",
              inventoryMaterialId: "",
              isUsed: 0,
              manufactureTime: "",
              materialCode: "",
              materialDetailSerials: [
                {
                  changeTime: "",
                  createTime: "",
                  id: "",
                  inventoryId: "",
                  inventoryMaterialId: "",
                  isUsed: 0,
                  materialDetailId: "",
                  remark: "",
                  serialCode: "",
                  userId: "",
                },
              ],
              materialId: "",
              materialModel: "",
              materialName: "",
              netAmount: "",
              orderCode: "",
              payableCloseStatus: "",
              payableCloseTime: "",
              planTrackingCode: "",
              price: "",
              priceCap: "",
              priceCoefficient: "",
              priceDiscount: "",
              priceFloor: "",
              pricingNum: "",
              pricingUnit: "",
              receivedNum: "",
              remark: "",
              requireTrackingCode: "",
              returnRelatedNum: "",
              sampleDestructionNum: "",
              serialCodeUnit: "",
              serialCodeUnitNum: "",
              serialCodeUpload: "",
              shelfLifeCycle: "",
              sourceDocCode: "",
              sourceDocType: "",
              supplierBatchNum: "",
              taxAmount: "",
              taxAmountBase: "",
              taxRate: "",
              totalTaxPrice: "",
              totalTaxPriceBase: "",
              userId: "",
              validTo: "",
              warrantyTime: "",
              warrantyUnit: "",
            },
            materialId: "",
            materialModel: "",
            materialName: "",
            moneyAmount: "",
            netPrice: "",
            pricingNum: "",
            pricingUnit: "",
            purchaseNum: 0,
            purchaseUnit: "",
            receiptsNum: "",
            receivableNum: "",
            relationCode: "",
            relationId: "",
            remark: "",
            sourceMaterialDetailId: "",
            sourceType: "",
            userId: "",
            warehouseCode: "",
            warehouseId: "",
            warehousePosition: "",
          };
      this.formObject.materialLists.push(obj);
    },
    handleDataDelete(index, row) {
      this.$confirm("请确认是否要删除此行？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.formObject.materialLists.splice(index, 1);
          this.num = this.num - 1;
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    addNewRow() {
      this.num = this.num + 1;
      this.handleDataAdd();
    },
    submit() {
      this.$refs["formRef"].validate((valid) => {
        if (!valid) {
          this.$message.error("请填写完整信息！");
          return;
        }
        // TODO 提交表单
        this.formObject.businessType = "21";
        (this.formObject.modelId =
          this.$store.state.workflow.businessConfig.id),
          (this.formObject.id = new Date());
        addKingInventoryList(this.formObject).then((res) => {
          if (res.code === 200) {
            this.$message({
              message: "新增成功！",
              type: "success",
            });
          }
        });
      });
    },
  },
  created() {},
};
</script>

<style lang="scss" scoped>
.divider {
  margin: 0;
}
.el-icon-search {
  margin-top: 70% !important;
}
</style>
